<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){
            var app4 = new Vue({
                el: '#app-4',
                methods:{
                    reverseMessage:function(){
                        this.todos.push({name: this.name,age: this.age});
                    },
                    removeMessage:function(){
                        this.todos.removeMessage();
                    },
                    removeall: function () {
                        this.todos=[];
                    },
                    remove: function (index) {
                        this.todos.splice(index,1);
                    }
                },
                data: {
                    todos: [

                    ]
                }
            })}
    </script>


</head>
<body>

<div id="app-4">
    <button v-on:click="reverseMessage">添加</button>
    <button v-on:click="removeall">全部删除</button>
    <input v-model="name">
    <input v-model="age">
    <table border="1">
        <tr>
            <th>序号</th><th>姓名</th><th>年龄</th><th>操作</th>
        </tr>
        <tr v-for="(todo,index) in todos">
            <td>{{ index+1 }}</td><td>{{ todo.name }}</td><td>{{ todo.age }}</td>
            <td><button v-on:click="remove(index)">删除</button></td>
        </tr>
    </table>
</div>
</body>
</html>